package logic

import (
	"context"
	"three-sxp/goodsrpc/goodsrpcclient"

	"three-sxp/api/internal/svc"
	"three-sxp/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodsLogic {
	return &CreateGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGoodsLogic) CreateGoods(req *types.CreateaGoodsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.GoodsRpc.CreateGoods(l.ctx, &goodsrpcclient.CreateGoodsRequest{
		GoodsName:    req.GoodsName,
		GoodsPrice:   float32(req.GoodsPrice),
		GoodsStock:   int64(req.GoodsStock),
		GoodsDetails: req.GoodsDetails,
	})
	if res.Code != 200 {
		return &types.Response{
			Code: int(res.Code),
			Msg:  res.Msg,
		}, nil
	}
	return &types.Response{
		Code: int(res.Code),
		Msg:  res.Msg,
	}, nil
}
